package com.lux.product.views {
	import com.greensock.easing.Linear;
	import com.greensock.easing.Quad;
	import com.greensock.TweenMax;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.display.MovieClip;

	/**
	 * @author shrek.wang
	 */
	public class McFlare extends MovieClip 
	{
		private var thisTimer:Timer;
		private var easeDuration:Number = 0.5;
		
		public function McFlare() 
		{
			init();
		}
		
		public function init():void
		{
			this.scaleX = this.scaleY = 0.1;
			this.alpha = 0;
			this.visible = false;
			this.rotation = 0;
			
			initTimer();
		}
		
		public function clear():void
		{
			clearTimer();
		}

		private function initTimer():void
		{
			clearTimer();
			
			thisTimer = new Timer(1000+int(Math.random()*3000),1);
			thisTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerHandler);
			thisTimer.start();
		}
		
		private function clearTimer():void
		{
			if(thisTimer)
			{
				thisTimer.stop();
				thisTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerHandler);
			}
		}
		
		private function onTimerHandler(event : TimerEvent) : void 
		{
			var _scale:Number = Math.random()*0.2+0.2;
			TweenMax.to(this,easeDuration, {autoAlpha:1, scaleX:_scale, scaleY:_scale, ease:Quad.easeIn, onComplete:motionInOver});
			TweenMax.to(this,easeDuration, {rotation:180, ease:Linear.easeIn});
		}
		
		private function motionInOver():void
		{
			TweenMax.to(this,easeDuration, {autoAlpha:0, scaleX:0.1, scaleY:0.1, ease:Quad.easeIn, onComplete:motionOutOver});
			TweenMax.to(this,easeDuration, {rotation:360, ease:Linear.easeOut});
		}
		
		private function motionOutOver():void
		{
			initTimer();
		}
		
		
	}
}
